function GM:PlayerSpawnSENT( ply, class )
	
	local enttab = scripted_ents.GetStored( class );
	local enttab2 = scripted_ents.GetStored( class );
	
	if( enttab.Base ) then
		
		enttab2 = scripted_ents.GetStored( enttab.Base );
		
	end
	
	if( enttab.t.Cosmic or enttab2.t.Cosmic ) then
		
		C.PCM( ply, Vector( 200, 0, 0 ), "Spawn Cosmos entities from the Cosmos tab!" );
		return false;
		
	end
	
	return self.BaseClass:PlayerSpawnSENT( ply, class );
	
end

local function CanPlayerSpawnSENT( ply, class )
	
	local e = scripted_ents.GetStored( class )
	if (e == nil) then 
	
		return false
	
	end

	local e = e.t
	
	if( !e.SpawnFunction ) then return false end
	
	if( !e.Spawnable and !ply:IsAdmin() ) then return false end 
	if( e.AdminOnly and !ply:IsAdmin() ) then return false end
	
	return true
	
end

function CCSpawnCosmos( player, command, arguments ) -- sandbox

	local EntityName = arguments[1]
	if ( EntityName == nil ) then return end
	
	if ( !CanPlayerSpawnSENT( player, EntityName ) ) then return end
	
	local sent = scripted_ents.GetStored( EntityName );
	
	if( sent.t.CosmicPrice ) then
		
		if( C.HasCredits( player, sent.t.CosmicPrice ) ) then
			
			C.RemoveCredits( player, sent.t.CosmicPrice );
			
		else
			
			return;
			
		end
		
	end
	
	local vStart = player:GetShootPos()
	local vForward = player:GetAimVector()
	
	local trace = {}
	trace.start = vStart
	trace.endpos = vStart + (vForward * 2048)
	trace.filter = player
	
	local tr = util.TraceLine( trace )
	
	local entity = nil
	local PrintName = nil
	
	ClassName = EntityName
		entity = sent.t:SpawnFunction( player, tr )
	ClassName = nil
	
	PrintName = sent.t.PrintName
	
	if ( ValidEntity( entity ) ) then
		
		gamemode.Call( "PlayerSpawnedSENT", player, entity )
		
		undo.Create("SENT")
			undo.SetPlayer(player)
			undo.AddEntity(entity)
			if ( PrintName ) then
				undo.SetCustomUndoText( "Undone "..PrintName )
			end
		undo.Finish( "Cosmos Entity - ".. ( PrintName or EntityName ) );
		
		player:AddCleanup( "sents", entity )		
		entity:SetVar( "Player", player )
		
		player:SendLua ( "surface.PlaySound( \"ui/buttonclickrelease.wav\" ) " )
		
		entity.Owner = player;
	
	end
	
end
concommand.Add( "c_spawnent", CCSpawnCosmos )

function GM:CanTool( ply, tr, tool )
	
	if( tool == "duplicator" and tr.Entity and tr.Entity:IsValid() and tr.Entity.Cosmic ) then
		
		return false;
		
	end
	
	return self.BaseClass:CanTool( ply, tr, tool );
	
end